package edu.hawaii.stack;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;

import org.junit.Ignore;
import org.junit.Test; 
import java.util.ArrayList;

/**
 * Test case for the ClearStack abstract data type, which checks to see that a ClearStack
 * containing three elements can be iterated through and that this iteration retrieves the
 * elements in the correct order. 
 *
 * @author Philip Johnson
 */
public class TestClearStack {

  // Objects used for testing.
  final Integer one = Integer.valueOf(1);
  final Integer two = Integer.valueOf(2);
  final Integer three = Integer.valueOf(3);
  final Integer four = Integer.valueOf(4);

  /**
   * Test the ClearStack iterator.
   * 
   * @throws EmptyStackException
   * @exception EmptyStackException If stack is empty.
   */
  @Test
  public void testNormalOperation() throws EmptyStackException {
    ClearStack stack = new ClearStack();
    stack.push(one);
    stack.push(two);
    stack.push(three);
    ArrayList<Object> list = new ArrayList<Object>();
    // Go through the elements in the stack and save them in an ArrayList.
    for (Object element : stack) {
      list.add(element);
    }
    // Now check to see they were there and in the right order.
    assertSame("Testing ClearStack[0]", one, list.get(0));
    assertSame("Testing ClearStack[1]", two, list.get(1));
    assertSame("Testing ClearStack[2]", three, list.get(2));
   
    assertSame("Testing getTop of stack same as three", three, stack.getTop());
   
    assertFalse("Testing Stack not Empty", stack.isEmpty());
    stack.pop();
    stack.pop();
    stack.pop();
    assertTrue("Testing Stack is Empty", stack.isEmpty());
    
    }
  /**
   * Bug for Emma but still get 100% line coverage.
   * To try it, delete the @Ignore and add @Test.
   */
  @Ignore
  public void bugEmma() {
    ClearStack stack2 = new ClearStack();
    stack2.push(one);
    stack2.push(two);
    stack2.push(three);
    ArrayList<Object> list2 = new ArrayList<Object>(2);
    
    for (int i = 0; i < 1000000000; i++) {
      list2.add(one);
    }
  }
   
}
